const cache = new Map<string | symbol, any>()

export async function withCache<R>(key: string | symbol, getter: IFn<R>): Promise<Awaited<R>> {
  if (cache.has(key)) {
    return JSON.parse(cache.get(key))
  }
  const value = await getter()
  cache.set(key, JSON.stringify(value))
  return value
}
